// 主程序

import 'reflect-metadata'  // 用于在运行时访问和操作装饰器的元数据。
import Koa from "koa"
import { useContainer, useKoaServer } from "routing-controllers";
import Container from "typedi";  // di 依赖注入
import { routingConfigs } from "./routing.options";
import { useMiddlewares } from "./koa.middlewares";

const createServer = async(): Promise<Koa> => {
    const koa: Koa = new Koa();

    // 使用中间件
    useMiddlewares(koa);

    useContainer(Container)

    // 路由
    const app: Koa = useKoaServer<Koa>(koa, routingConfigs);

    return app;
}

export default createServer